Array.prototype.myReduce = function (fn, res) {
  let i = 0;
  if (typeof res == "undefined") {
    res = this[0];
    i++;
  }
  for (i; i < this.length; i++) {
    res = fn(res, this[i], i);
  }
  return res;
};

console.log(
  [1, 2, 3].myReduce((a, b) => {
    return a + b;
  })
);
